from pyson.gen import string, struct, array, PysonObject, boolean, PysonObjectMeta, number

class AbstractMessage(PysonObject):
    msgType = string()

    def __init__(self, messageType):
        self.msgType = messageType

class EditContext(PysonObject):
    name = string()
    page = string()
    canMoveBack = boolean()

    def __init__(self, contextName, pageId, canMoveBack):
        self.name = contextName
        self.page = pageId
        self.canMoveBack = canMoveBack

class AbstractServerMessage(AbstractMessage):
    def __init__(self, messageType):
        self.__super.__init__(messageType)

class AbstractContextualServerMessage(AbstractServerMessage):
    context = struct()

    def __init__(self, messageType, ctx):
        self.__super.__init__(messageType)
        self.context = ctx

class EditCookie(AbstractContextualServerMessage):
    fields = array(struct)

    def __init__(self, ctx, fieldBuilders):
        self.__super.__init__("EditCookie", ctx)
        self.fields = fieldBuilders

class Hints(AbstractContextualServerMessage):
    items = array(struct)

    def __init__(self, ctx, itemBuilders):
        self.__super.__init__("Hints", ctx)
        self.items = itemBuilders

class ResultStarterReady(AbstractContextualServerMessage):
    def __init__(self, ctx):
        self.__super.__init__("ResultStarterReady", ctx)

class Result(AbstractContextualServerMessage):
    content = string()

    def __init__(self, ctx, cont):
        self.__super.__init__("Result", ctx)
        self.content = cont

class End(AbstractContextualServerMessage):
    def __init__(self):
        self.__super.__init__("End", EditContext("", "", 0))

class ProjectEntries(AbstractServerMessage):
    #entries = struct()
    entries = array(struct)

    def __init__(self, entryBuilders):
        self.__super.__init__("ProjectEntries")
        self.entries = entryBuilders
#        entryBuildersDict = {}
#        for entryBuilder in entryBuilders:
#            entryBuildersDict[entryBuilder.id] = struct(entryBuilder)
#
#        dynBuilderCls = PysonObjectMeta("DynamicEntriesBuilder", (PysonObject,), entryBuildersDict)
#
#        self.entries = dynBuilderCls()
